<template>
  <div style="padding: 0">
    <div style="margin-top: -30px; margin-bottom: -30px; padding: 0px">
      <el-input
        placeholder="请输入内容"
        prefix-icon="el-icon-search"
        v-model="searchCon"
        style="width: 500px"
      >
      </el-input>
      <el-button type="primary" style="margin-left: 100px">搜索</el-button>
    </div>
    <el-table
      :data="tableData"
      style="width: 1200px; margin-left: 50px; margin-right: 50px"
    >
      <el-table-column prop="goods_id" label="ID" width="50px">
      </el-table-column>
      <el-table-column prop="goods_name" label="商品名称" width="300px">
      </el-table-column>
      <el-table-column prop="goods_price" label="商品价格" width="300px">
      </el-table-column>
      <el-table-column prop="goods_num" label="商品库存" width="300px">
      </el-table-column>
      <el-table-column prop="goods_type" label="商品类型" width="100px">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">删除</el-button>
          <el-button type="text" size="small" @click="editGood(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData: this.$store.state.myGoodsData,
      searchCon: "",
    };
  },
  methods: {
     handleClick(row) {
        let goods = {
          'goods_id':row.goods_id
        };
        this.axios.post("/api/shopping/deleteGoods.php",goods).then(res=>{
          if(res.data=="ok"){
            alert("删除成功");
          }else if(res.data=="error"){
            alert("删除失败");
          }else{
            alert("服务器繁忙,请稍后重试");
          }
        });
      },
      editGood(row){
        this.$store.dispatch('setGoodsid',row.goods_id);
        this.$store.dispatch('setGoodsname',row.goods_name);
        this.$store.dispatch('setGoodsprice',row.goods_price);
        this.$store.dispatch('setGoodsnum',row.goods_num);
        this.$store.dispatch('setGoodstype',row.goods_type);
        this.$router.push({name:'editmygoods',params:{id:row.goods_id}});
      }
  },
};
</script>